// custom-tab-bar/index.js
/* 小程序组件生命周期：created、attached、ready、moved、detached、error */
const app = getApp()
Component({
  data: {
    tabbarLists: [
      {
        "pagePath": "/pages/main/main",
        "iconPath": "/images/tabbar/main.png",
        "selectedIconPath": "/images/tabbar/mainActive.png",
        "name":"首页",
        "type": ""
      },
      {
        "pagePath": "/pages/statistics/statistics",
        "iconPath": "/images/tabbar/statistics.png",
        "selectedIconPath": "/images/tabbar/statisticsActive.png",
        "name":"课程",
        "type": ""
      },
      {
        "pagePath": "/pages/information/information",
        "iconPath": "/images/tabbar/info.png",
        "selectedIconPath": "/images/tabbar/infoActive.png",
        "name":"消息",
        "type": "information"
      },
      {
        "pagePath": "/pages/myInfo/myInfo",
        "iconPath": "/images/tabbar/my.png",
        "selectedIconPath": "/images/tabbar/myActive.png",
        "name":"我的",
        "type": ""
      }
    ],
    active:null, //设为数字，会产生tabbar闪烁
    isShow:true, //控制显示隐藏tabbar 
    count:app.globalData.informationCount,//消息总数
    countNumber:0,
  },
  observers:{
    'count': function (val) {
      this.setData({countNumber:val})
      // console.log("tab消息查看",val,this.data.count,this.data.countNumber)
    }
  },
  lifetimes: {
    attached(){
      if(app.globalData.informationCount == 0){
          this.getMessageNumber()
      }
      this.setData({count:app.globalData.informationCount})
    },
  },
  methods: {
    switchTab(e){
      const { index,url } = e.currentTarget.dataset;
      wx.switchTab({url})
    },
    /* 获取消息类型数据 */
    getMessageNumber(){
      if(wx.getStorageSync('userType') == '2'){
        app.get(app.globalApis.informationApi.getMessageNumberApi).then(res=>{
          if(res.code == 0){
              this.setData({count:res.data})
          }
        })
      }
    },
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})